<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/11
 * Time: 14:52
 */
use doumiaoduo\layer\LayerConfirmWidget;
use doumiaoduo\layer\LayerIframeWidget;
use common\components\helpers\Fun;
use common\components\extenders\MenuManage;

use doumiaoduo\layer\LayerAsset;
LayerAsset::register($this);

LayerConfirmWidget::widget();
LayerIframeWidget::widget();
?>
    <div class="yx-cnt-box yx-praise-content yx-radius2">
        <div class="yx-praise-box">
            <a href="<?=Fun::url(['isusercommission/index'])?>" class="btn yx-back-list yx-radius5 ">返回</a>
            <div class="yx-member-info">
                <h3 class="yx-pb15">结算:</h3>
                <table class="yx-member-box yx-member-box1">
                    <tr>
                        <td bgcolor="#f8f8f8">发卡人</td>
                        <td><?=$data['salesman']?></td>
                        <td bgcolor="#f8f8f8">订单数</td>
                        <td id="orders_count"><?=$data['orders_count']?></td>
                        <td bgcolor="#f8f8f8">需结算总金额</td>
                        <td id="settlement_amount"><?=$data['settlement_amount']?></td>
                        <td bgcolor="#f8f8f8">佣金总金额</td>
                        <td id="commission_money"><?=$data['commission_money']?></td>
                    </tr>
                </table>
            </div>

            <div class="yx-member-info">
                <h3 class="yx-pb15">明细:</h3>
                <table class="yx-member-box yx-member-box1" id="balance-table" style="width: 100%">
                    <?php foreach ($data['details'] as $k=>$v) { ?>
                        <tr id = <?=$v['id'] ?>>
                            <td bgcolor="#f8f8f8">ID</td>
                            <td><?=$v['id'] ?></td>
                            <td bgcolor="#f8f8f8">订单号</td>
                            <td><?=$v['orders'] ?></td>
                            <td bgcolor="#f8f8f8">创建时间</td>
                            <td><?=$v['created_at']?></td>
                            <td bgcolor="#f8f8f8">需结算金额</td>
                            <td class="settlement_amount"><?=$v['settlement_amount']?></td>
                            <td bgcolor="#f8f8f8">佣金</td>
                            <td class="commission_money"><?=$v['commission_money']?></td>
                            <td bgcolor="#f8f8f8">操作</td>
                            <td><a class="btn yx-radius2 yx-d-card yx-bg65d1d4 remove_tr"
                                ">移除</a></td>
                        </tr>
                    <?php } ?>
                </table>
            </div>
            <div style="margin: 10px">
            <span>
                <a class='yx-radius2 yx-batch-settlement' id='dobalance'>确认结算</a>
                <a class='yx-batch-settlement yx-bg7ecef4 yx-ml10 yx-radius2' onclick="javascript:history.back(-1);">返回列表</a>
            </span>
            </div>

        </div>
    </div>

<?php
$js = <<<JS
    $('.remove_tr').click(function(){
        $(this).parent().parent().remove();
        var orders_count_all = parseInt($('#orders_count').html());
        var settlement_amount_all = parseFloat($('#settlement_amount').html());
        var commission_money_all = parseFloat($('#commission_money').html());
        
        var settlement_amount = parseFloat($(this).parent().parent().find('td[class="settlement_amount"]').html());
        var commission_money = parseFloat($(this).parent().parent().find('td[class="commission_money"]').html());
        
        var orders_count_alls = orders_count_all - 1;
        var settlement_amount_alls = settlement_amount_all - settlement_amount;
        var commission_money_alls = commission_money_all - commission_money;
        
        $('#orders_count').html(orders_count_alls);
        $('#settlement_amount').html(settlement_amount_alls);
        $('#commission_money').html(commission_money_alls);
    });

    $('#dobalance').click(function(){
        var tt = $("#balance-table tr");
         var contrTemp=[];
        for(var i=0;i<tt.length;i++){
            contrTemp.push(tt[i].id);
        }
        if(contrTemp.length == 0){
              layer.msg('没有要结算的项！',{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
            return false;
        }
        var str = contrTemp.join(',');
        $.ajax({  
            url:'/isusercommission-dobalance',
            traditional :true,
            data:{  
                orders_commission_ids : str
            },  
            type:'post',  
            cache:false,  
            dataType:'json',  
            success:function(data) {  
                alert(data.resault);
                if(data.url == ''){
                    window.location.reload();
                }else{
                    $(location).attr('href', data.url);
                }
            }
        });
    });
JS;
$this->registerJs($js);
?>